package com.sungrowpower.kit.customview;

import android.graphics.Color;

import org.json.JSONException;
import org.json.JSONObject;

public class SGAvatarItemMap {
    //头像形状 圆形 true 非圆 false
    public boolean isOver;
    //头像的src
    public int src;
    //头像宽度
    public int avatarWidth;
    //头像的高度
    public int avatarHeight;
    //头像的背景颜色
    public int avatarBackgroundColor;
    //头像的边框的宽
    public int avatarBorderWidth;
    //边框的背景颜色
    public int avatarBorderBackgroundColor;
    //头像中中 icon 的宽
    public int avatarIconWidth;
    //头像中的背景颜色
    public int avatarIconBackgroundColor;
    //设置头像中间字体的名称
    public String avatarCenterName;
    //设置头像中间的字体的颜色
    public int avatarCenterTextColor;
    //设置头像中间字体的大小
    public int avatarCenterTextSize;
    //字体加粗
    public boolean isCenterBold;


    //方形圆角的大小
    public int avatarRadiusSize = 4;
    //头像标题文本颜色
    public int  avatarTitleColor;
    //头像标题文本的大小
    public int avatarTitleSize = 14;
    //头像标题文本的内容
    public String avatarTitleWord;
    //头像内容文本的颜色
    public int avatarContentColor;
    //头像内容文本的大小
    public int avatarContentSize;
    //头像内容文本的内容
    public String avatarContentWord;
    //头像内容到文本到顶部的距离
    public int avatarMarginTopSize = 14;
    //设置最后被完成的背景
    public boolean mIsLastComplete = false;
    //显示底部内容
    public boolean avatarBottomTextShow = false;

    //显示中间的内容
    public boolean avatarCenterTextShow;

    //设置头像底部字体的名称
    public String avatarBottomName;

    //设置头像底部字体的颜色
    public int avatarBottomTextColor;

    //设置底部字体的大小
    public int avatarBottomTextSize;

    //设置圆的半径
    public int mRadius;
    //设置间距的比例
    public float mSpace;

    //设置最大数目
    public int mMaxCount;

    //设置显示头像右下角的小图标
    public boolean isShowRightIcom = false;
    //设置右边小图标的宽
    public int rightIcomWidth;
    //设置右边小图标的高
    public int rightIcomHeight;
    //奢姿最右边小图标的背景颜色
    public int rightIcomBackgroundColor;
    //自定义头像右边的小图标是不是显示
    public boolean isShowRightSmallIcon = false;


    private static class Holder{
        private static final SGAvatarItemMap INSTANCE = new SGAvatarItemMap();
    }
    public static SGAvatarItemMap getInstance(){
        return Holder.INSTANCE;
    }

    public void parseJson(String json,AvatarItemBean avatarItemBean){
        try {
            JSONObject jsonObject = new JSONObject(json);
             isOver = jsonObject.getBoolean("isOver");
             src = jsonObject.optInt("src");
            avatarWidth = jsonObject.optInt("avatarWidth",40);
            avatarHeight = jsonObject.optInt("avatarHeight",40);
            avatarBackgroundColor = Color.parseColor(jsonObject.optString("avatarBackgroundColor"));
            avatarBorderWidth = jsonObject.optInt("avatarBorderWidth");
            avatarBorderBackgroundColor = Color.parseColor(jsonObject.optString("avatarBorderBackgroundColor"));
            avatarIconWidth = jsonObject.optInt("avatarIconWidth",4);
            avatarIconBackgroundColor = Color.parseColor(jsonObject.optString("avatarIconBackgroundColor"));
            avatarCenterName = jsonObject.optString("avatarCenterName");
            avatarCenterTextColor = Color.parseColor(jsonObject.optString("avatarCenterTextColor"));
            avatarCenterTextSize = jsonObject.optInt("avatarCenterTextSize");
            avatarCenterTextSize = jsonObject.optInt("mMaxCount");
            mMaxCount = jsonObject.optInt("avatarBottomTextColor");
            avatarBottomTextSize = jsonObject.optInt("avatarBottomTextSize");
            mSpace = (float) jsonObject.optDouble("mSpace");
            avatarRadiusSize = jsonObject.getInt("avatarRadiusSize");
            avatarTitleColor = Color.parseColor(jsonObject.optString("avatarTitleColor"));
            avatarTitleSize = jsonObject.getInt("avatarTitleSize");
            avatarTitleWord = jsonObject.getString("avatarTitleWord");
            avatarBottomName = jsonObject.getString("avatarBottomName");
            avatarContentColor = Color.parseColor(jsonObject.optString("avatarContentColor"));
            avatarContentSize = jsonObject.getInt("avatarContentSize");
            avatarContentWord = jsonObject.getString("avatarContentWord");
            avatarMarginTopSize = jsonObject.getInt("avatarMarginTopSize");
            mIsLastComplete = jsonObject.optBoolean("mIsLastComplete");
            avatarBottomTextShow = jsonObject.optBoolean("avatarBottomTextShow",false);
            avatarCenterTextShow = jsonObject.optBoolean("avatarCenterTextShow",false);
            mRadius = jsonObject.optInt("mRadius");
            isCenterBold = jsonObject.optBoolean("isCenterBold");
            isShowRightIcom = jsonObject.getBoolean("isShowRightIcom");
            rightIcomWidth = jsonObject.getInt("rightIcomWidth");
            rightIcomHeight = jsonObject.getInt("rightIcomHeight");
            rightIcomBackgroundColor = Color.parseColor(jsonObject.optString("rightIcomBackgroundColor"));
            isShowRightSmallIcon = jsonObject.getBoolean("isShowRightSmallIcon");

            avatarItemBean.setOver(isOver)
                    .setSrc(src)
                    .setAvatarWidth(avatarWidth)
                    .setAvatarHeight(avatarHeight)
                    .setAvatarBackgroundColor(avatarBackgroundColor)
                    .setAvatarBorderWidth(avatarBorderWidth)
                    .setAvatarBorderBackgroundColor(avatarBorderBackgroundColor)
                    .setAvatarIconWidth(avatarIconWidth)
                    .setRightIcomHeight(rightIcomHeight)
                    .setAvatarIconBackgroundColor(avatarIconBackgroundColor)
                    .setAvatarCenterName(avatarCenterName)
                    .setAvatarCenterTextColor(avatarCenterTextColor)
                    .setAvatarCenterTextSize(avatarCenterTextSize)
                    .setAvatarRadiusSize(avatarRadiusSize)
                    .setAvatarRadiusSize(avatarRadiusSize)
                    .setAvatarTitleWord(avatarTitleWord)
                    .setAvatarTitleColor(avatarTitleColor)
                    .setAvatarTitleSize(avatarTitleSize)
                    .setAvatarCenterName(avatarCenterName)
                    .setAvatarCenterTextSize(avatarContentSize)
                    .setAvatarCenterTextColor(avatarCenterTextColor)
                    .setAvatarMarginTopSize(avatarMarginTopSize)
                    .setmIsLastComplete(mIsLastComplete)
                    .setmRadius(mRadius)
                    .setRightIcomWidth(rightIcomWidth)
                    .setRightIcomHeight(rightIcomHeight)
                    .setRightIcomBackgroundColor(rightIcomBackgroundColor)
                    .setShowRightSmallIcon(isShowRightSmallIcon);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
